﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace VetumaForSP2010.Configuration
{
    public class SharePointGroups : ConfigurationElementCollection
    {
        public SharePointGroup this[int index]
        {
            get
            {
                if (index < 0)
                {
                    throw new ArgumentOutOfRangeException("Index cannot be smaller than 0.");
                }
                if (index >= base.Count)
                {
                    throw new ArgumentOutOfRangeException("Index cannot be bigger or same than an amount of configuration elements.");
                }
                else
                {
                    return base.BaseGet(index) as SharePointGroup;
                }
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new SharePointGroup();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((SharePointGroup)element).GroupName;
        }
    }
}
